from django.contrib import admin
from django.contrib.contenttypes.admin import GenericTabularInline

from content import models


class AdditionalyPhraseWordInline(GenericTabularInline):

    model = models.Additionaly
    max_num = 1


@admin.register(models.Word)
class WordAdmin(admin.ModelAdmin):

    list_display = ['translate', 'word', 'part_of_speech', 'updated', 'created']
    prepopulated_fields = {'slug': ('word',)}


@admin.register(models.Verb)
class VerbAdmin(admin.ModelAdmin):

    inlines = [AdditionalyPhraseWordInline]
    list_display = ['translate', 'word', 'simple_past', 'past_participle', 'part_of_speech', 'updated', 'created']
    readonly_fields = ['updated', 'created']
    prepopulated_fields = {'slug': ('word',)}



@admin.register(models.PartOfSpeech)
class PartOfSpeechAdmin(admin.ModelAdmin):
    list_display = ['name']
    prepopulated_fields = {'slug': ('name',)}


@admin.register(models.Phrase)
class PhraseForm(admin.ModelAdmin):
    inlines = [AdditionalyPhraseWordInline]
    list_display = ['phrase', 'translation']
    prepopulated_fields = {'slug': ('phrase',)}


@admin.register(models.Additionaly)
class AdditionalyAdmin(admin.ModelAdmin):
    list_fields = ['note', 'photo']


@admin.register(models.Rule)
class RuleAdmin(admin.ModelAdmin):
    list_fields = ['title', 'description', 'group', 'slug']
    prepopulated_fields = {'slug': ('title',)}


@admin.register(models.Image)
class ImageAdmin(admin.ModelAdmin):
    list_fields = ['title', 'description', 'photo', 'group', 'slug']
    prepopulated_fields = {'slug': ('title',)}
